package com.leetcode.string;

public class LengthOfLastWord {
    public int lengthOfLastWord(String s) {
        int len = 0;
        String str = s.trim();
        for (int i = str.length() - 1; i >= 0; i--) {
            if (str.charAt(i) == ' ') {
                break;
            } else {
                len++;
            }
        }
        return len;
    }
}
